<?php
class Toko_Dao{

	
	function __construct(){
			$koneksi = new Koneksi();
			$koneksi->_connect();
	}
	
	function add(Toko $toko){
		
		$sql = "
			INSERT 
			INTO
			toko
			(
				id_toko,
				nama_toko,
				alamat,
				kota,
				kodepos,
				telp,
				email,
				nama_bank,
				cabang,
				atas_nama,
				rek,
				deskripsi_toko,
				tgl_daftar
			)
			VALUES
			(
				'".$toko->id_toko."',
				'".$toko->nama_toko."',
				'".$toko->alamat."',
				'".$toko->kota."',
				'".$toko->kodepos."',
				'".$toko->telp."',
				'".$toko->email."',
				'".$toko->nama_bank."',
				'".$toko->cabang."',
				'".$toko->atas_nama."',
				'".$toko->rek."',
				'".$toko->deskripsi_toko."',
				'".$toko->tgl_daftar."'
			)
		";
		//print_r($sql);
		
		mysql_query($sql);
		
		//if($hasil){
		//	var_dump($hasil);
		//}
	
	}
	
	function get($id_toko){
	
		
		$sql = "
		SELECT
		*
		FROM
		toko
		WHERE
		id_toko = '".$id_toko."'
		";
		
		$toko = false;
		
		$res = mysql_query($sql);
		
		if($res){
		
			$row = mysql_fetch_assoc($res);
		
			$toko = new Toko();
				$toko->id_toko = $row['id_toko'];
				$toko->nama_toko = $row['nama_toko'];
				$toko->alamat = $row['alamat'];
				$toko->kota = $row['kota'];
				$toko->kodepos = $row['kodepos'];
				$toko->telp = $row['telp'];
				$toko->email = $row['email'];
				$toko->nama_bank = $row['nama_bank'];
				$toko->cabang = $row['cabang'];
				$toko->atas_nama = $row['atas_nama'];
				$toko->rek = $row['rek'];
				$toko->deskripsi_toko = $row['deskripsi_toko'];
				$toko->tgl_daftar = $row['tgl_daftar'];
		}
		
		return $toko;
	}
	
	function get_all(){
	
		
		$sql = "
		SELECT
		*
		FROM
		toko
		";
		
		$list_toko = array();
		
		$res = mysql_query($sql);
		if($res){
			while($row = mysql_fetch_assoc($res)){
			
				$toko = new Toko();
				
				$toko->id_toko = $row['id_toko'];
				$toko->nama_toko = $row['nama_toko'];
				$toko->alamat = $row['alamat'];
				$toko->kota = $row['kota'];
				$toko->kodepos = $row['kodepos'];
				$toko->telp = $row['telp'];
				$toko->email = $row['email'];
				$toko->nama_bank = $row['nama_bank'];
				$toko->cabang = $row['cabang'];
				$toko->atas_nama = $row['atas_nama'];
				$toko->rek = $row['rek'];
				$toko->deskripsi_toko = $row['deskripsi_toko'];
				$toko->dtgl_daftar = $row['tgl_daftar'];
				$list_toko[] = $toko;
			
			}
		}
		return $list_toko;
	
	}
	function edit(Toko $toko){
		$sql ="
			UPDATE 
			toko
			SET
			nama_toko='$toko->nama_toko',
			alamat='$toko->alamat',
			kota='$toko->kota',
			kodepos='$toko->kodepos',
			telp='$toko->telp',
			email='$toko->email',
			nama_bank='$toko->nama_bank',
			cabang='$toko->cabang',
			atas_nama='$toko->atas_nama',
			rek='$toko->rek',
			deskripsi_toko='$toko->deskripsi_toko',
			tgl_daftar='$toko->daftar_toko'
			WHERE 
			id_toko ='$toko->id_toko'
		";
		mysql_query($sql);
	
	}
	function hapus($id_toko){
	
		$sql = "
		DELETE
		FROM
		toko
		WHERE
		id_toko = '".$id_toko."'
		";
		
		mysql_query($sql);
	
	}

}

class Toko{

	var $id_toko;
	var $nama_toko;
	var $alamat;
	var $kota;
	var $kodepos;
	var $telp;
	var $email;
	var $nama_bank;
	var $cabang;
	var $atas_nama;
	var $rek;
	var $deskripsi_toko;
	var $tgl_daftar;
	}

